草庐IT

JavaScript window.opener 调用父函数

全部标签

javascript - 在一个成功的内部进行 ajax 调用可以被认为是不好的做法吗?

让我们来看下面的一段代码:$.ajax({type:'POST',dataType:dataType,url:'someUrl',success:function(result){$.ajax({type:'POST',dataType:dataType,url:'anotherUrl',data:queryToSearch,success:function(anotherResult){(dosomethingthatusesthefirstoneresult)},error:MyObj.defaultAjaxError});},error:MyObj.defaultAjaxErro

javascript - 没有每个和回调函数的 jQuery 循环

我希望在没有each和回调调用的情况下循环抛出jQuery集合。我有以下代码varfound1=false;$('#Rootdiv.ListItem').each(function(index,d1){if(group==d1.text()){found1=true;}});if(found1){return;}Oncefound1设置为true下一次它总是true。我想知道如何在没有each和回调的情况下循环for(varidin$('#Rootdiv.ListItem')){...}更新我不知道如何打破循环。我不想在each中传递回调如果我在循环中传递jQuery对象,那么我会得到

javascript - 通过ajax调用传递给mvc Controller 时在列表中获取空值

我正在将我的列表传递给一个mvcController,但我在Controller中得到的是空值。但是当在客户端显示为警报时,我的列表有值。ajax调用$("#addTiles").click(function(){userTiles=JSON.stringify({'userTiles':userTiles});alert("Enteredfunction.");alert(userTiles[0].TileID);varurl='@Url.Action("AddTiles")';$.ajax({type:"GET",url:url,data:userTiles,success:fun

javascript - 理解函数的原型(prototype)属性

举个例子如果varFunc=function(){}这里的Func有一个名为prototype的属性,我可以像下面这样添加我的自定义方法。Func.prototype.move=function(){//dosomething}根据我的理解,原型(prototype)只是Func的另一个属性,它默认由解释器提供,不用于委托(delegate)任何功能,即。没有什么比Func.move()应用相同的逻辑,我正在创建相同功能的另一个属性,如下所示Func.method=function(){//dosomething}现在如果创建一个新对象varobj=newFunc();这里有obj.m

javascript - TypeError : $(. ..)DataTable 不是一个函数

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭7年前。Improvethisquestion我正在尝试使用jquery插件数据表,但我似乎无法加载该函数。我不断收到此错误:UncaughtTypeError:$(...).DataTableisnotafunction(anonymousfunction)@index.php:167m.Callbacks.j@jquery.min.js:2

javascript - instanceof 在 JavaScript 中的函数

面试的第一个问题,老实说,我看到自己真的很困惑,就把门关了,考虑片段:案例一:varsayHello=newFunction("alert('Hellothere');");alert(sayHelloinstanceofFunction);//truealert(sayHelloinstanceofObject);//true,sinceevery//objectinheritsfromObject情况b:varmyFunction=function(){}varins=newmyFunction();alert(insinstanceofmyFunction);//ofcourse

javascript - 如何在 Javascript 中的 array.forEach 中等待异步函数

我正在尝试在foreach中发出一个async请求以获取数据以便稍后用户使用它,但它对我不起作用。我知道Array.Foreach是一个同步函数,所以我什至尝试了$.when.done但它仍然不会等到它完成。如果它是单个值但它是一个数组,我本可以使用回调。有没有更好的方法通过回调来处理这个问题,以实现在下一步移动之前等待async请求?browseItems.forEach((browseItem:any)=>{AsynchFunction();cosole.log("Step2")}functionAsynchFunction(){console.log("Step1")}我正在尝试

javascript - 测试调用 API 的 redux 操作

测试此功能的最佳方法是什么exportfunctionreceivingItems(){return(dispatch,getState)=>{axios.get('/api/items').then(function(response){dispatch(receivedItems(response.data));});};}这是我目前拥有的describe('ItemsActionCreator',()=>{it('shouldcreateareceivingitemsfunction',()=>{expect(receivingItems()).to.be.a.function;

javascript - 为什么我不能在 JavaScript/ES6 中使用带有箭头函数的 `new`?

据我所知,箭头函数类似于普通函数。我这样使用没有任何问题:letX=()=>{};letY=function(){};X();Y();但是,当我将它们与new一起使用时,出现了错误:letX=()=>{};letY=function(){};x=newX();y=newY();未捕获的类型错误:X不是构造函数这是为什么? 最佳答案 问。我做错了什么?A.您将new与箭头函数一起使用,这是不允许的。问。我可以将箭头函数转换为构造函数吗?A.仅将其包装在普通函数中,这很愚蠢。您不能将箭头函数本身变成构造函数。问。您能解释一下规范如何禁止

javascript - 具有命名函数的 window.removeEventListener 不起作用

我正在使用React,下面是我用来实现无限滚动功能的代码。componentDidMount(){//Flagtocheckifthecontenthasloaded.letflag=true;functioninfiniteScroll(){letenterpriseWrap=$('.enterprise-blocks');letcontentHeight=enterpriseWrap.offsetHeight;letyOffset=window.pageYOffset;lety=yOffset+window.innerHeight;console.log('hey');if(thi